package com.platform.cdcs.fragment.detail;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import com.platform.cdcs.R;
import com.platform.cdcs.adapter.ProductItemAdatper;
import com.platform.cdcs.model.ProductList;
import com.platform.cdcs.tool.FragmentUtil;
import com.sherchen.slidetoggleheader.views.ObservableXListView;
import com.trueway.app.uilib.fragment.BaseFragment;
import com.trueway.app.uilib.tool.Utils;

/**
 * Created by holytang on 2017/11/21.
 */
public class ProductListFragment extends BaseFragment {
    ProductList dataList;
    private ProductItemAdatper adatper;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        adatper = new ProductItemAdatper(getContext());
        adatper.setModel(4);
        dataList = (ProductList) getArguments().getSerializable("model");
        adatper.setItemListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ProductList.ProductItem item = (ProductList.ProductItem) view.getTag(R.mipmap.ic_launcher);
                Bundle bundle = new Bundle();
                bundle.putSerializable("model", item);
                bundle.putInt("type",1);
                FragmentUtil.navigateToInNewActivity(getActivity(), ProductInfoFragment.class, bundle);
            }
        });
        adatper.addAll(dataList.getProductList());
    }

    @Override
    public void initView(View view) {
        initLoadImg(view.findViewById(R.id.load));
        setHasOptionsMenu(true);
        hideThisToolBar(view);
        setTitle("产品");
        getToolBar().setNavigationIcon(R.mipmap.icon_back);
        getToolBar().setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getActivity().finish();
            }
        });
        TextView textView = new TextView(getContext());
        textView.setText("序列号");
        textView.setTextSize(12);
        textView.setTextColor(ContextCompat.getColor(getContext(),R.color.text_hint));
        int paddingx = Utils.convertDIP2PX(getContext(), 15);
        textView.setPadding(paddingx, paddingx / 2, paddingx, paddingx / 2);
        ObservableXListView slideListView = (ObservableXListView) view.findViewById(android.R.id.list);
        slideListView.addHeaderView(textView);
        slideListView.setPullRefreshEnable(false);
        slideListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                i = i - 2;
                Utils.showToast(getContext(), String.valueOf(i));
            }
        });
        slideListView.setAdapter(adatper);
    }

    @Override
    public int layoutId() {
        return R.layout.listview;
    }
}
